Skip to content

Comments

chore(deps): update dependency kysely-codegen to v0.20.0#77

Open
renovate[bot] wants to merge 1 commit intomainfrom
renovate/kysely-codegen-0.x
Open

chore(deps): update dependency kysely-codegen to v0.20.0#77
renovate[bot] wants to merge 1 commit intomainfrom
renovate/kysely-codegen-0.x

Conversation

@renovate
Copy link
Contributor

@renovate renovate bot commented Sep 9, 2025

This PR contains the following updates:

Package Change Age Confidence
kysely-codegen 0.18.50.20.0 age confidence

Release Notes

RobinBlomberg/kysely-codegen (kysely-codegen)

v0.20.0

Compare Source

Many great contributions, bug fixes and new features.

Resolves #​284, #​287, #​307, #​308, #​72, #​301, #​275, #​283.

defineConfig() and postprocess()

kysely-codegen@​0.20.0 adds a defineConfig function that makes it easy to configure kysely-codegen in a type-safe way. It also adds a new Config#postprocess function that makes it possible to process the introspected metadata before generating code. This function allows you to reuse the active kysely-codegen connection to further introspect the database and modify the metadata as needed.

Example of generating enum types from PostGraphile enum tables:

import { sql } from "kysely";
import { defineConfig } from "kysely-codegen";
import pluralize from "pluralize";

export default defineConfig({
  camelCase: false,
  dateParser: "timestamp",
  dialect: "postgres",
  excludePattern: "(graphile_migrate.*|graphile_worker._private_*)",
  outFile: "./types/database-types.ts",
  postprocess: async ({ db, metadata }) => {
    const rows = await db
      .selectFrom("pg_catalog.pg_constraint as foreign_key_constraint")
      .innerJoin(
        "pg_catalog.pg_class as from_table",
        "from_table.oid",
        "foreign_key_constraint.conrelid",
      )
      .innerJoin(
        "pg_catalog.pg_namespace as from_table_namespace",
        "from_table_namespace.oid",
        "from_table.relnamespace",
      )
      .innerJoin("pg_catalog.pg_attribute as from_column", (join) =>
        join
          .onRef("from_column.attrelid", "=", "from_table.oid")
          .on(sql`from_column.attnum = any(foreign_key_constraint.conkey)`),
      )
      .innerJoin(
        "pg_catalog.pg_class as to_table",
        "to_table.oid",
        "foreign_key_constraint.confrelid",
      )
      .innerJoin(
        "pg_catalog.pg_namespace as to_table_namespace",
        "to_table_namespace.oid",
        "to_table.relnamespace",
      )
      .innerJoin("pg_catalog.pg_attribute as to_column", (join) =>
        join
          .onRef("to_column.attrelid", "=", "to_table.oid")
          .on(sql`to_column.attnum = any(foreign_key_constraint.confkey)`),
      )
      .select([
        "from_table_namespace.nspname as fromSchema",
        "from_table.relname as fromTable",
        "from_column.attname as fromColumn",
        "to_table_namespace.nspname as enumSchema",
        "to_table.relname as enumTable",
        "to_column.attname as enumColumn",
      ])
      .where("foreign_key_constraint.contype", "=", "f")
      .where(sql<any>`obj_description(to_table.oid, 'pg_class') like '%@&#8203;enum%'`)
      .execute();

    await Promise.all(
      rows.map(
        async ({
          fromColumn,
          fromSchema,
          fromTable,
          enumColumn,
          enumSchema,
          enumTable,
        }) => {
          const fromTableMetadata = metadata.tables.find(
            (table) => table.schema === fromSchema && table.name === fromTable,
          );
          const fromColumnMetadata = fromTableMetadata?.columns.find(
            (column) => column.name === fromColumn,
          );
          const enumTableMetadata = metadata.tables.find(
            (table) => table.schema === enumSchema && table.name === enumTable,
          );
          const enumColumnMetadata = enumTableMetadata?.columns.find(
            (column) => column.name === enumColumn,
          );

          if (fromColumnMetadata || enumColumnMetadata) {
            const dataType = `${pluralize.singular(enumTable)}.${enumColumn}`;
            const enumValues = await db
              .selectFrom(`${enumSchema}.${enumTable}`)
              .select(enumColumn)
              .execute()
              .then((rows) =>
                rows.map((row) => (row as Record<string, string>)[enumColumn]),
              );

            metadata.enums.set(`${enumSchema}.${dataType}`, enumValues);

            if (fromColumnMetadata) {
              fromColumnMetadata.dataTypeSchema = enumSchema;
              fromColumnMetadata.dataType = dataType;
            }

            if (enumColumnMetadata) {
              enumColumnMetadata.dataTypeSchema = enumSchema;
              enumColumnMetadata.dataType = dataType;
            }
          }
        },
      ),
    );

    return metadata;
  },
  singularize: true,
  url: process.env.DATABASE_URL,
});

Example output:

+type EventTypeName = "TICKET_CREATED" | "TICKET_DELETED" | "TICKET_UPDATED";
+
 type Event = {
   createdAt: Generated<Timestamp>;
   data: JsonValue;
-  type: string;
+  type: EventTypeName;
 };

 type EventType = {
   description: string;
-  name: string;
+  name: EventTypeName;
 };

What's Changed

New Contributors

Full Changelog: RobinBlomberg/kysely-codegen@0.19.0...0.20.0

v0.19.0

New features

Thanks to amazing contributions from @​kevinmichaelchen in #​274, you can now override types on a global level:

.kysely-codegenrc.json

{
  "customImports": {
    "InstantRange": "./custom-types",
    "CustomDuration": "@&#8203;my-org/custom-types#Duration",
    "Temporal": "@&#8203;js-temporal/polyfill",
  },
  "typeMapping": {
    "timestamptz": "Temporal.Instant",
    "tstzrange": "InstantRange",
    "date": "Temporal.PlainDate",
    "interval": "CustomDuration"
  }
}

Example of generated output:

import type { InstantRange } from './custom-types';
import type { Duration as CustomDuration } from '@&#8203;my-org/custom-types';
import type { Temporal } from '@&#8203;js-temporal/polyfill';

export interface EventModel {
  createdAt: Temporal.Instant;
  dateRange: ColumnType<InstantRange, InstantRange, never>;
  eventDate: Temporal.PlainDate;
  interval: CustomDuration;
}

export interface DB {
  events: EventModel;
}

What's Changed

New Contributors

Full Changelog: RobinBlomberg/kysely-codegen@0.18.0...0.19.0


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot requested a review from a team as a code owner September 9, 2025 21:30
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch 3 times, most recently from b2ed715 to a2e8323 Compare September 29, 2025 07:52
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch 4 times, most recently from 93357ee to 16da347 Compare October 8, 2025 06:50
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch 2 times, most recently from e8c77b4 to 01665be Compare October 22, 2025 07:06
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch from 01665be to 7661da8 Compare November 10, 2025 21:37
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch from 7661da8 to 00ed11c Compare November 18, 2025 22:58
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch from 00ed11c to fa0e59b Compare December 3, 2025 19:08
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch from fa0e59b to 5c21727 Compare December 31, 2025 12:56
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch from 5c21727 to 6c95fe3 Compare January 8, 2026 20:24
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch from 6c95fe3 to edd7fcf Compare January 23, 2026 18:43
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch from edd7fcf to b1b86c2 Compare February 2, 2026 17:40
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch 3 times, most recently from dfb7b1b to d12c1d1 Compare February 19, 2026 08:49
@renovate renovate bot changed the title chore(deps): update dependency kysely-codegen to v0.19.0 chore(deps): update dependency kysely-codegen to v0.20.0 Feb 19, 2026
@renovate renovate bot force-pushed the renovate/kysely-codegen-0.x branch from d12c1d1 to 272aac6 Compare February 20, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants